import 'package:flutter_oldman_health/utils/http_util.dart';
import 'constant.dart';

class FamilyMemberService {
  //获取所属家庭成员列表
  static Future queryFamilyRelation() async {
    var result = await HttpUtil.get(Constant.host +
        '/manager/medical/user/${Constant.enterpriseId}/relation');
    return result;
  }

  //添加家庭成员
  static Future addFamilyRelation({String memberId, String phone}) async {
    var result;
    if (phone != null) {
      result = await HttpUtil.post(
          Constant.host +
              '/manager/medical/user/${Constant.enterpriseId}/relation',
          data: {"phone": phone});
    } else if (memberId != null&&memberId.length>4) {
      result = await HttpUtil.post(
          Constant.host +
              '/manager/medical/user/${Constant.enterpriseId}/relation',
          data: {"memberId": memberId});
    }
    return result;
  }

  //修改家庭成员
  static Future editFamilyRelation(String memberId, String alias) async {
    var result = await HttpUtil.put(
        Constant.host +
            '/manager/medical/user/${Constant.enterpriseId}/relation',
        data: {"memberId": memberId, "alias": alias});
    return result;
  }

  //成员添加确认  废弃
  static Future confirmFamilyRelation(String memberId) async {
    var result = await HttpUtil.get(
        Constant.host +
            '/manager/medical/user/${Constant.enterpriseId}/confirm',
        queryParams: {
          "memberId": memberId,
        });
    return result;
  }

  //获取成员信息  获取家庭成员信息
  static Future queryMemberInfo(String memberId) async {
    var result = await HttpUtil.get(Constant.host +
        '/manager/medical/user/${Constant.enterpriseId}/relation/$memberId');
    return result;
  }

  //获取成员信息
  static Future deleteMember(String memberId) async {
    var result = await HttpUtil.delete(Constant.host +
        '/manager/medical/user/${Constant.enterpriseId}/relation/$memberId');
    return result;
  }

  //查询用户距离限制信息
  static Future queryDistanceLimitList(String limitedId) async {
    var result = await HttpUtil.get(
        Constant.host +
            '/manager/medical/user/${Constant.enterpriseId}/distance_limit/list',
        queryParams: {"limitedId": limitedId});
    return result;
  }

  //enterpriseId	是	String	path	企业id
  // id	是	String	body	限制信息id
  // limitedId	是	String	body	被限制人id
  // longitude	是	Double	body	原始位置经度
  // latitude	是	Double	body	原始位置纬度
  // distance	是	Integer	body	限制取域半径
  // remind	是	Integer	body	是否提醒；0：不提醒，1：提醒
  //增加用户距离限制信息
  static Future createDistanceLimit(String limitedId, double longitude,
      double latitude, int distance, int remind) async {
    var result = await HttpUtil.post(
        Constant.host +
            '/manager/medical/user/${Constant.enterpriseId}/distance_limit',
        data: {
          "limitedId": limitedId,
          "longitude": longitude,
          "latitude": latitude,
          "distance": distance,
          "remind": remind
        });
    return result;
  }

  //删除
  static Future deleteDistanceLimit(String id) async {
    print("deleteDistanceLimit$id");
    var result = await HttpUtil.delete(Constant.host +
        '/manager/medical/user/${Constant.enterpriseId}/distance_limit/$id');
    return result;
  }

  //修改用户距离限制信息
  static Future updateDistanceLimit(String id, String limitedId,
      double longitude, double latitude, int distance, int remind) async {
    var result = await HttpUtil.post(
        Constant.host +
            '/manager/medical/user/${Constant.enterpriseId}/distance_limit',
        data: {
          "id": id,
          "limitedId": limitedId,
          "longitude": longitude,
          "latitude": latitude,
          "distance": distance,
          "remind": remind
        });
    return result;
  }
}
